package com.klangner.go.model.impl;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;

import com.klangner.go.model.BoardPosition;
import com.klangner.go.model.IStonesGroup;




// class for a group of stones
/**
 * Represents group of stones with information about it
 */
public class StonesGroup implements IStonesGroup{

	/** Stones color */
	private int color;

	/** stones list */
  private Vector<BoardPosition>	stones;

	/** liberties list */
  private Set<BoardPosition>	liberties;

  /**
   * constructor; each group has at least one stone 
   * @param stone
   */
  public StonesGroup(int color) {

  	this.color = color;
    stones = new Vector<BoardPosition>();
    liberties = new HashSet<BoardPosition>();
  }

  /**
   * Add liberty to the group
   */
  public void addLiberty(BoardPosition position){

  	liberties.add(position);
  }
  
  /**
   * Add stone to the group
   */
  public void addStone(BoardPosition position){

  	stones.add(position);
  }
  
  /**
   * @return stones color
   */
  public int getColor(){
  	return color;
  }
  
  /**
   * @return group liberties 
   */
  public Collection<BoardPosition>	getLiberties(){
  	return liberties;
  }
  
  /**
   * @return stones collection 
   */
  public Collection<BoardPosition>	getStones(){
  	return stones;
  }
  
  /**
   * @return number of liberties
   */
//  public int nrLiberties() {
//  	return liberties.size();
//  }

  /**
   * Convert to string
   */
  public String toString() {
      return "[" + color + "; " + "S=" + stones + ";L=" + 0 +"]";
  }

  /** 
   * Merge stones from another group into this one
   * @param stonesGroup
   */
	public void merge(StonesGroup stonesGroup) {

		Iterator<BoardPosition> it = stonesGroup.getStones().iterator();
		
		while( it.hasNext() ){
			addStone(it.next());
		}
	}

}
